package com.scada.controller;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.scada.model.bean.PermissionRole;
import com.scada.model.result.ResponseBean;
import com.scada.service.PermissionRoleService;


/**
 * @author 黄胜
 * 16-10-26 11:24
 * 系统权限角色方法
 *  
 */
@Controller
@RequestMapping("permissionRole")
public class PermissionRoleController extends BaseController{

	@Autowired
	private PermissionRoleService permissionRoleService;
	
	@RequestMapping("selectPermissionByRoleKey")
	@ResponseBody
	public List<PermissionRole> selectPermissionByRoleKey(Integer roleId){
		if(roleId != null){
			return (List<PermissionRole>)permissionRoleService.selectPermissionByRoleKey(roleId).getObject("perList");
		}
		return null;
	}
	
	@RequestMapping("savePermissionByRoleKey")
	@ResponseBody
	public ModelAndView savePermissionByRoleKey(Integer roleId, @RequestParam(value = "ids[]")Integer[] ids){
		ResponseBean rb = new ResponseBean();
		if(roleId == null && roleId != 0){
			rb.failed("角色ID错误");
		}else{
			rb = permissionRoleService.savePermissionByRoleKey(roleId, ids);
			if(StringUtils.equals(ResponseBean.SUCCESS, rb.getType())){
				rb.success("保存成功");
			}else{
				rb.failed("保存失败");
			}
		}
		return rb.getJsonModelView();
	}
}
